package com.equipment;

import java.util.NoSuchElementException;

import com.util.EncodingUtil;

/**
 * 国标读车辆信息应答D2
 * @author Administrator
 *
 */
public class ReadChineseVehicleResponse {
	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 数据长度
	private String code = "FD"; // 代码
	private String broadening = "D2"; // 扩展代码
	private String bcc = "";// 异或校验
	private String status = "";// 状态
	private String vehicleInfo = ""; // 车辆信息79字节

	/**
	 * 解析数据帧
	 * @param context
	 * @throws NoSuchElementException
	 */
	public void analysis(String context)
			throws NoSuchElementException {
		if (!context.substring(12, 14).equals("D2")) {
			throw new NoSuchElementException("读车辆命令字错误");
		}
		// 判断是否成功
		if (!context.substring(14, 16).equals("00")) {
			throw new NoSuchElementException("读车辆失败："+EncodingUtil.getErrorResult(EncodingUtil.hexToDec(context.substring(14, 16))));
		}
		status = context.substring(14, 16);
		vehicleInfo = context.substring(16, context.length()-2);
	}

	public String getSTX() {
		return STX;
	}

	public void setSTX(String sTX) {
		STX = sTX;
	}

	public String getRSCTL() {
		return RSCTL;
	}

	public void setRSCTL(String rSCTL) {
		RSCTL = rSCTL;
	}

	public String getLength() {
		return Length;
	}

	public void setLength(String length) {
		Length = length;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getBroadening() {
		return broadening;
	}

	public void setBroadening(String broadening) {
		this.broadening = broadening;
	}

	public String getBcc() {
		return bcc;
	}

	public void setBcc(String bcc) {
		this.bcc = bcc;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getVehicleInfo() {
		return vehicleInfo;
	}

	public void setVehicleInfo(String vehicleInfo) {
		this.vehicleInfo = vehicleInfo;
	}


}
